#include <bits/stdc++.h>
using namespace std;

void solve() {
    int a[4];
    for(int i = 0; i < 4; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i < 4; i++) {
        if(a[i] > a[0]) ans++;
    }
    cout << ans << endl;
}

signed main() {
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}